<template>
	<view class="rank-page">
		<u-navbar :autoBack="true" :placeholder="true" bgColor="rgba(0, 0, 0, 0.0)">
			<view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" color="#fff" size="24"></u-icon>
			</view>
			<view class="u-nav-slot" slot="center">
				<view class="nav-text">
					积分排行榜
				</view>
			</view>
		</u-navbar>
		<view class="content">
			<view class="tabs">
				<view :class="item.show == true?'activity-item':''" class="tabs-item" v-for="(item,index) in tabs"
					:key="index" @click="cutTabs(index)">
					{{item.text}}
				</view>
			</view>
			<scroll-view scroll-y="true" class="scroll">
				<view class="list" v-if="list.length > 0">
					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="item-left">
							<view class="num">
								{{index + 1}}
							</view>
							<view class="head">
								<image
									:src="item.avatar.startsWith('http') ? item.avatar : 'https://m.lqvvvv.com' + item.avatar || 'https://m.lqvvvv.com/assets/static/index/head.png'"
									mode="aspectFill">
								</image>
							</view>
							<view class="info">
								<view class="name">
									{{item.nickname}}
								</view>
								<view class="id">
									ID:{{item.user_id}}
								</view>
							</view>
						</view>
						<view class="integral">
							<image src="https://m.lqvvvv.com/images/integral.png" mode=""></image>
							<view class="integral-text">
								积分：{{item.total_score}}
							</view>
						</view>
					</view>
				</view>
				<view v-else>
					<u-empty mode="list" :marginTop="100" icon="http://cdn.uviewui.com/uview/empty/list.png">
					</u-empty>
				</view>
			</scroll-view>
			<view v-if="token!=''">
				<view class="my-box" v-if="info.avatar">
					<view class="item">
						<view class="item-left">
							<view class="num">
								{{info.rank}}
							</view>
							<view class="head">
								<image :src="'https://m.lqvvvv.com'+info.avatar" mode=""></image>
							</view>
							<view class="info">
								<view class="name">
									{{info.nickname}}
								</view>
								<view class="id">
									{{info.user_id}}
								</view>
							</view>
						</view>
						<view class="item-right">
							<view class="integral">
								<image src="https://m.lqvvvv.com/images/integral.png" mode=""></image>
								<view class="integral-text">
									积分：{{info.total_score}}
								</view>
							</view>
							<view class="convert">
								<image @click="goexchange" src="https://m.lqvvvv.com/images/convert.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
				<view class="my-box" v-else>
					<view class="item">
						<view class="item-left">
							<view class="num" style="width: 100rpx;">
								未上榜
							</view>
							<view class="head">
								<image :src="'https://m.lqvvvv.com'+userinfo.avatar" mode=""></image>
							</view>
							<view class="info">
								<view class="name">
									{{userinfo.nickname}}
								</view>
								<view class="id">
									{{userinfo.id}}
								</view>
							</view>
						</view>
						<view class="item-right">
							<view class="integral">
								<image src="https://m.lqvvvv.com/images/integral.png" mode=""></image>
								<view class="integral-text">
									积分：0
								</view>
							</view>
							<view class="convert">
								<image @click="goexchange" src="https://m.lqvvvv.com/images/convert.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [{
						text: '日榜',
						show: true
					},
					{
						text: '周榜',
						show: false
					},
					{
						text: '月榜',
						show: false
					}
				],
				list: [],
				type: 'day',
				info: {},
				userinfo: {},
				token:''
			}
		},
		onLoad() {
			this.getlist()
			this.token = uni.getStorageSync("token") || '';
			if (this.token != '') {
				this.myinfo()
				this.getuserinfo()
			}
			console.log(this.token)
			
		},
		methods: {
			// /api/index/rankList
			getuserinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/user/getMyInfo',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.userinfo = res.data
					} else {
						this.userinfo = {}
					}
				})
			},
			myinfo() {
				let app = this
				let params = {
					type: this.type,

				}
				app.$Request({
					method: 'POST',
					url: '/api/user/myScoreRank',
					data: params,
					isFormData: true,
					ismsg: false,
				}).then(res => {
					console.log(res)
					this.info = res.data
				})
			},
			async getlist() {
				const params = {
					type: this.type,
					page: 1,
					limit: 20
				};
				const res = await this.$Request({
					method: 'POST',
					url: '/api/index/scoreRankList',
					data: params,
					ismsg: false,
				});

				if (res.code === 1) {
					// 更新列表数据
					this.list = res.data.data
				}
			},
			cutTabs(index) {
				this.tabs.map(item => {
					item.show = false
				})
				this.tabs[index].show = true
				if (index == 0) {
					this.type = 'day'
				}
				if (index == 1) {
					this.type = 'month'
				}
				if (index == 2) {
					this.type = 'year'
				}
				this.getlist()
				let token = uni.getStorageSync("token") || '';
				if (token != '') {
					this.myinfo()
				}
				
				
			},
			goexchange() {
				uni.navigateTo({
					url: '/pages/index/rank/exchange'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.rank-page {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		padding: 60rpx 30rpx 30rpx 30rpx;

		.nav-text {
			font-size: 36rpx;
			font-weight: bold;
			color: #fff;
		}

		.content {
			padding-top: 20rpx;
			position: relative;

			.tabs {
				width: 75%;
				display: flex;
				justify-content: space-between;
				margin: 0 auto;
				background-color: pink;
				border-radius: 50rpx;
				padding: 10rpx;
				background-color: rgba(255, 255, 255, 0.6);

				.tabs-item {
					width: 30%;
					color: rgba(105, 27, 172, 0.36);
					font-size: 32rpx;
					font-weight: bold;
					padding: 20rpx;
					text-align: center;
				}

				.activity-item {
					width: 30%;
					background: linear-gradient(180deg, #B76CF7 0%, #5755F2 100%);
					color: #fff;
					border-radius: 40rpx;
					text-align: center;
				}
			}

			.scroll {
				border-radius: 30rpx;
				background-color: #fff;
				min-height: 60vh;
				padding: 10rpx 20rpx 20rpx 20rpx;
				width: 95%;
				margin: 0 auto;
				margin-top: 20rpx;
				box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.1);
			}

			.list {
				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 30rpx;

					.item-left {
						display: flex;
						align-items: center;

						.num {
							width: 50rpx;
							font-size: 28rpx;
							color: #2D2D2D;
							font-weight: bold;
							text-align: center;
							margin-right: 10rpx;
						}

						.head {
							border-radius: 50%;
							width: 82rpx;
							height: 82rpx;

							image {
								width: 82rpx;
								height: 82rpx;
								border-radius: 50%;
								box-shadow: 0rpx 4rpx 14rpx 0rpx rgba(143, 69, 255, 0.5);
							}
						}

						.info {
							margin-left: 20rpx;
							font-size: 28rpx;

							.name {
								color: #2D2D2D;
							}

							.id {
								color: #9D97B2;
								margin-top: 10rpx;
								font-size: 26rpx;
							}
						}
					}

					.integral {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						color: #9D97B2;

						image {
							width: 42rpx;
							height: 42rpx;
							margin-right: 10rpx;
						}
					}
				}
			}

			.my-box {
				width: 94%;
				border: 4rpx solid rgba(183, 108, 247, 1);
				padding: 20rpx;
				position: fixed;
				bottom: 80rpx;
				left: 0;
				right: 0;
				margin: 0 auto;
				border-radius: 30rpx;
				background: #E5E5FF;
				box-shadow: 0rpx 5rpx 17rpx 0rpx rgba(87, 85, 242, 0.13);

				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.item-left {
						display: flex;
						align-items: center;

						.num {
							width: 70rpx;
							font-size: 28rpx;
							color: #2D2D2D;
							font-weight: bold;
						}

						.head {
							border-radius: 50%;
							width: 82rpx;
							height: 82rpx;

							image {
								width: 82rpx;
								height: 82rpx;
								border-radius: 50%;
								box-shadow: 0rpx 4rpx 14rpx 0rpx rgba(143, 69, 255, 0.5);
							}
						}

						.info {
							margin-left: 20rpx;
							font-size: 28rpx;

							.name {
								color: #2D2D2D;
							}

							.id {
								color: #9D97B2;
								margin-top: 10rpx;
								font-size: 26rpx;
							}
						}
					}

					.item-right {
						.integral {
							display: flex;
							align-items: center;
							font-size: 24rpx;
							color: #9D97B2;

							image {
								width: 42rpx;
								height: 42rpx;
								margin-right: 10rpx;
							}
						}

						.convert {
							text-align: right;

							image {
								width: 148rpx;
								height: 65rpx;
							}
						}
					}
				}
			}
		}
	}
</style>